package com.example.mysmall.mvp_rajava.ui.modules.home;

import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.example.mysmall.mvp_rajava.R;
import com.example.mysmall.mvp_rajava.base.BaseFragment;
import com.example.mysmall.mvp_rajava.entity.LiveChina;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by xingge on 2017/8/15.
 */

public class HomeFragment extends BaseFragment implements HomeContract.View {
    @BindView(R.id.homeList)
    ListView homeList;
    private HomeAdapter adapter;
    private List<LiveChina.LiveBean> lives;
    private HomeContract.Presenter presenter;
    @Override
    public void setPresenter(HomeContract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void showMsg(String msg) {

        Toast.makeText(getActivity(),msg,Toast.LENGTH_LONG).show();
    }

    @Override
    public void showLiveChina(LiveChina liveChina) {

        lives.addAll(liveChina.getLive());
        adapter.notifyDataSetChanged();

    }

    @Override
    protected int getLayoutId() {
        return R.layout.home_fragment;
    }

    @Override
    protected void init(View view) {
        lives = new ArrayList<>();
        adapter = new HomeAdapter(getActivity(),lives);
        homeList.setAdapter(adapter);
    }

    @Override
    protected void loadData() {
        presenter.start();
    }

}
